<?php
class address
{	function showAddress($explodedAddress, $link="")
	{		$workdays=new workdays();		$addrElement=explode('^', $explodedAddress);
		$address=$addrElement[0].', '.$addrElement[1];
		if(!$addrElement[1])$address=$addrElement[0];
		$phone=$addrElement[2];
		$wDays=$addrElement[4];
		if($addrElement[3]!='')$mallElement=explode(',', $addrElement[3]);
		$mallId=$mallElement[0];
		$mallName=$mallElement[1];
		$mallShort=$mallElement[2];		echo ('		<table border="0">
			<tr>
				<td width="30">
					<img src="images/address.jpg" title="адрес">
				</td>
				<td width="266">
					'.$address.'<br />
					<font size="2" color="green">
						<a href="malls.php?city='.$_GET['city'].'&id='.$mallId.'" id="mallLink">
						'.$mallName.' '.$mallShort.'
						</a>
					</font>
				</td>
			</tr>
			');
		if($phone)
		{
			echo ('
			<tr>
				<td width="30">
					<img src="images/phone.jpg" title="телефон">
				</td>
				<td>
					'.$phone.'
				</td>
			</tr>
			');
		}
		if($wDays)
		{
			echo ('
			<tr>
				<td width="30">
					<img src="images/clock.jpg" title="часы работы">
				</td>
				<td>
					');
					$workdays->showWorkdays($wDays);
					echo ('
				</td>
			</tr>

			');
		}
		if($link)
		{			echo ('
			<tr>
				<td width="30">
					<img src="images/site.jpg" title="вэб-сайт">
				</td>
				<td>
					<a href="http://'.$link.'">www.'.$link.'</a>
				</td>
			</tr>
			');
		}
		echo ('
		</table>
		');	}
	function showSeveralAddresses($address, $link, $edit='')
	{		$explodedAddress=explode('|', $address);
		echo ('
		<script type="text/javascript" src="scripts/address.js">
		</script>
		<div id="mainAdr" style="display: block;">
		');
		if($edit)
			$this->showEditAddress($explodedAddress[0], $link);
		else
			$this->showAddress($explodedAddress[0], $link);
		if(count($explodedAddress)>1)
		{
			echo ('
			<div align="center">
				<p id="showAllLink"  style="display: block;" class="moreLink">
					Еще адреса
				</p>
			</div>
			');
		}
		echo ('
		</div>
		');
			echo ('
			<div id="allAdr" style="display: none;">
			');
				//$this->showAddress($explodedAddress[0], $link, $edit);
					echo ('

					');
				//}
			for($i=1; $i<count($explodedAddress); $i++)
			{				echo '<br />';
				$this->showAddress($explodedAddress[$i]);
			}
			echo ('
				<p id="closeAllAdr" class="moreLink">
					Закрыть
				</p>
			</div>
			');
	}
	function showEditAddress($explodedAddress, $link="")
	{		echo ('		<table border="0">
			<tr>
				<td width="30">
					<img src="images/address.jpg" title="адрес">
				</td>
				<td width="266">
					'.$address.'<br />
					<font size="2" color="green">
						<a href="malls.php?city='.$_GET['city'].'&id='.$mallId.'" id="mallLink">
						'.$mallName.' '.$mallShort.'
						</a>
					</font>
				</td>
			</tr>
			<tr>
				<td width="30">
					<img src="images/phone.jpg" title="телефон">
				</td>
				<td>
					'.$phone.'
				</td>
			</tr>
			<tr>
				<td width="30">
					<img src="images/clock.jpg" title="часы работы">
				</td>
				<td>
					'.$wDays.'
				</td>
			</tr>
		');
		if($link)
		{
			echo ('
			<tr>
				<td width="30">
					<img src="images/site.jpg" title="вэб-сайт">
				</td>
				<td>
					<a href="http://'.$link.'">www.'.$link.'</a>
				</td>
			</tr>
			');
		}
		echo ('
			<tr>
				<td width="30">
					<a href="#">Добавить адрес</a>
				</td>
				<td align="right">
					<a href="#">Изменить адрес</a>
				</td>
			</tr>
		</table>
		');
	}
	function showFormScripts()
	{
		echo ('		<script type="text/javascript" src="scripts/addressSuggest.js">
		</script>
		<link rel="stylesheet" type="text/css" href="style/addressform.css" />
		');	}
	function showForm($number, $value='', $valid='', $ask=false)
	{		if($ask)$ask=new ask();
		if($value)$value=explode(',', $value);
		$streetValue=$value[0];
		$buildingValue=$value[1];
		$mallId=$value[2];
		$mallName=$value[3];
		$mallShort=$value[4];
		echo ('
		<div class="addressForm">
			<div class="street">
				<div class="signature">
					Улица:
				');
				if($ask)$ask->askButton('streetask');
				echo ('
				</div>
				<div class="streetForm" id="streetForm'.$number.'">
					<input class="streetInput" name="street'.$number.'" id="street'.$number.'" type="text" value="'.$streetValue.'" placeholder="напр: Ленина" autocomplete="off">
				</div>
			</div>
			<div class="building">
				<div class="signature">
					Здание:
				');
				if($ask)$ask->askButton('buildingask');
				echo ('
				</div>
				<div class="buildingForm" id="buildingForm'.$number.'">
					<input class="buildingInput" name="building'.$number.'" id="building'.$number.'" type="text" placeholder="напр:13а/6" value="'.$buildingValue.'" autocomplete="off">
				</div>
				<div class="checkAddressRes" id="checkAddressRes'.$number.'">
					<img src="main_pics/nok.jpg" class="okpic" />
				</div>
			</div>
			<div class="streetSuggest" id="streetSuggest'.$number.'">
			</div>
			<div class="buildingSuggest" id="buildingSuggest'.$number.'">
			</div>
			<div class="mallSuggest" id="mallSuggest'.$number.'">
			');
			if($mallId)
			{
				echo ('
				'.$mallShort.' '.$mallName.'
				<input name="mallSuggest'.$number.'" id=="mallSuggest'.$number.'" type="checkbox" value="'.$mallId.','.$mallName.','.$mallShort.'" checked>
				<input name="mallHidden'.$number.'" id="mallHidden'.$number.'" type="hidden" value="'.$mallId.','.$mallName.','.$mallShort.'">
				');
			}
			echo ('
			</div>
		</div>
		');
	}}
?>